home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / misc / emu / ATUtilities.lha / ATUtilities / tr.byterotator < prev    next >
Text File  |  2000-09-26  |  34KB  |  1,385 lines

  1. /* ******************************************************************* */
  2. /* **                                                               ** */
  3. /* **                     ATUtilities Disk Transfer                 ** */
  4. /* **            Copright (C) 1992-1993 by Thomas Dreibholz         ** */
  5. /* **                      All rights reserved                      ** */
  6. /* **                                                               ** */
  7. /* ******************************************************************* */
  8.  
  9. #include <devices/trackdisk.h>
  10. #include "janus.h"
  11. #include "ATUtilities.h"
  12.  
  13. #define BIT15 (1<<15)
  14.  
  15. struct UDevice
  16. {
  17.  UBYTE              Name[100];
  18.  UWORD              Unit;
  19.  ULONG              Heads;
  20.  ULONG              SectorsPerTrack;
  21.  ULONG              Tracks;
  22.  UWORD              Motor;
  23.  BOOL               File;
  24. };
  25.  
  26. struct TDevice
  27. {
  28.  BOOL               Valid;
  29.  ULONG              Changes;
  30.  struct FileHandle *FileHandle;
  31.  struct IOStdReq   *Request;
  32.  struct MsgPort    *Port;
  33.  LONG               Device;
  34. };
  35.  
  36. struct UDevice ud[6]=
  37. {
  38.  "trackdisk.device",0,2,11,80,4,FALSE,
  39.  "trackdisk.device",1,2,11,80,4,FALSE,
  40.  "trackdisk.device",0,1,11,80,4,FALSE,
  41.  "trackdisk.device",1,1,11,80,4,FALSE,
  42.  "DH0:Trashcan/File01",0,2,11,80,0,TRUE,
  43.  "DH0:Trashcan/File02",0,4,16,200,0,TRUE
  44. };
  45.  
  46. struct TDevice td[6]=
  47. {
  48.  TRUE,10000000L,NULL,NULL,NULL,-1L,
  49.  TRUE,10000000L,NULL,NULL,NULL,-1L,
  50.  TRUE,10000000L,NULL,NULL,NULL,-1L,
  51.  TRUE,10000000L,NULL,NULL,NULL,-1L,
  52.  TRUE,10000000L,NULL,NULL,NULL,-1L,
  53.  TRUE,10000000L,NULL,NULL,NULL,-1L
  54. };
  55.  
  56. UWORD Active;
  57. UWORD MotorCNT[6]={0,0,0,0,0,0};
  58.  
  59. UBYTE *TransferPort="ATUtilities Disk Transfer";
  60. UBYTE *PrefsName="AT:Prefs/DiskTransfer.prefs";
  61. UBYTE *HelpName="AT:Help/DiskTransfer.help";
  62.  
  63. struct JanusBase *JanusBase;
  64. struct Library   *GfxBase;
  65. struct Library   *IntuitionBase;
  66. struct Library   *ATUtilitiesBase;
  67.  
  68. struct Process      *MotorTask;
  69. struct Task         *MainTask;
  70. struct MsgPort      *TaskPort,*ReplyPort;
  71. struct ExtSetupSig  *ExtSetupSig;
  72. struct Window       *WindowPtr;
  73. struct RastPort     *rp;
  74. struct CommMemory   *jhbyte,*jhword;
  75. struct AppManager   *app;
  76. struct Message       Message;
  77. struct Message      *AppMessage;
  78.  
  79. LONG  JanusSignal;
  80. LONG  PortSignal;
  81. LONG  TaskSignal;
  82. ULONG JanusSignalMask;
  83. ULONG PortSignalMask;
  84. ULONG WaitSignalMask;
  85. ULONG TaskSignalMask;
  86. ULONG AppSignalMask;
  87. ULONG Signale;
  88.  
  89. VOID HandleInt();
  90. VOID ShowInfo();
  91. VOID Motor();
  92. VOID EditiereLW();
  93. VOID ZeigeLW();
  94. BOOL EinstellungenAendern();
  95. VOID InstallAll();
  96. VOID UninstallAll();
  97. VOID InstallFile();
  98. VOID UninstallFile();
  99. VOID InstallDevice();
  100. VOID UninstallDevice();
  101. VOID OpenAll();
  102. VOID CloseAll();
  103. VOID Bearbeite();
  104. VOID BearbeiteFile();
  105. WORD ChangeCheck();
  106. VOID CalcFAT();
  107. VOID MotorOnOff();
  108. VOID Format();
  109. VOID Kopiere();
  110.  
  111. UBYTE           *mem;
  112. struct MsgPort  *Port;
  113.  
  114.  
  115. /* Installationsroutine */
  116. VOID main()
  117. {
  118.  REGISTER UWORD i;
  119.  REGISTER BOOL  bool;
  120.  
  121.  OpenAll();
  122.  bool=FALSE;
  123.  while(bool==FALSE)
  124.   {
  125.    Signale=Wait(WaitSignalMask);
  126.    if(Signale & PortSignalMask)
  127.     {
  128.      i=Received(Port);
  129.      switch(i)
  130.       {
  131.        case UTILITY_CALL:
  132.          bool=EinstellungenAendern();
  133.         break;
  134.        case UTILITY_QUIT:
  135.          bool=ExitWarning();
  136.         break;
  137.        case UTILITY_INFO:
  138.          ShowInfo();
  139.         break;
  140.        case UTILITY_HELP:
  141.          Help(HelpName,0);
  142.         break;
  143.       }
  144.     }
  145.    if(Signale & JanusSignalMask)
  146.     {
  147.      HandleInt();
  148.     }
  149.    if(Signale & TaskSignalMask)
  150.     {
  151.      for(i=0;i<6;i++)
  152.       {
  153.        if(MotorCNT[i]>0)
  154.         {
  155.          MotorCNT[i]--;
  156.          if(MotorCNT[i]==0) MotorOnOff(i,0);
  157.         }
  158.       }
  159.     }
  160.    if(app!=NULL)
  161.     {
  162.      if(Signale & AppSignalMask)
  163.       {
  164.        AppMessage=GetMsg(app->Port);
  165.        if(AppMessage!=NULL)
  166.         {
  167.          ReplyMsg(AppMessage);
  168.          bool=EinstellungenAendern();
  169.         }
  170.       }
  171.     }
  172.   }
  173.  CloseAll();
  174. }
  175.  
  176.  
  177. /* PC-Befehle ausführen */
  178. VOID HandleInt()
  179. {
  180.  UWORD i,l;
  181.  
  182.  switch(jhword->Arg1)
  183.   {
  184.    case 1:
  185.      if(ud[Active].File==FALSE)
  186.       {
  187.        MotorCNT[Active]=ud[Active].Motor;
  188.        td[Active].Request->io_Data=mem;
  189.        l=jhword->Arg2*512;
  190.        CopyMemQuick(&jhword->Memory,mem,l);
  191.        td[Active].Request->io_Data=mem;
  192.        td[Active].Request->io_Length=l;
  193.        td[Active].Request->io_Offset=jhword->Arg3*512;
  194.        td[Active].Request->io_Command=CMD_WRITE;
  195.        i=DoIO(td[Active].Request);
  196.        if(i!=0)
  197.         {
  198.          switch(i)
  199.           {
  200.            case 28:
  201.              jhword->Arg2=0+BIT15;
  202.             break;
  203.            case 29:
  204.              jhword->Arg2=15+BIT15;
  205.             break;
  206.            default:
  207.              jhword->Arg2=10+BIT15;
  208.             break;
  209.           }
  210.         }
  211.        else
  212.         {
  213.          jhword->Arg2=0;
  214.         }
  215.       }
  216.      else
  217.       {
  218.        l=jhword->Arg2*512;
  219.        Seek(td[Active].FileHandle,jhword->Arg3*512,OFFSET_BEGINNING);
  220.        i=Write(td[Active].FileHandle,&jhword->Memory,l);
  221.        if(i==l)
  222.         {
  223.          jhword->Arg2=0;
  224.         }
  225.        else
  226.         {
  227.          jhword->Arg2=10+BIT15;
  228.         }
  229.       }
  230.     break;
  231.    case 2:
  232.      if(ud[Active].File==FALSE)
  233.       {
  234.        MotorCNT[Active]=ud[Active].Motor;
  235.        td[Active].Request->io_Data=mem;
  236.        l=jhword->Arg2*512;
  237.        td[Active].Request->io_Length=l;
  238.        td[Active].Request->io_Offset=jhword->Arg3*512;
  239.        td[Active].Request->io_Command=CMD_READ;
  240.        i=DoIO(td[Active].Request);
  241.        if(i!=0)
  242.         {
  243.          switch(i)
  244.           {
  245.            case 29:
  246.              jhword->Arg2=15+BIT15;
  247.             break;
  248.            default:
  249.              jhword->Arg2=11+BIT15;
  250.             break;
  251.           }
  252.         }
  253.        else
  254.         {
  255.          CopyMemQuick(mem,&jhword->Memory,l);
  256.          jhword->Arg2=0;
  257.         }
  258.       }
  259.      else
  260.       {
  261.        l=jhword->Arg2*512;
  262.        Seek(td[Active].FileHandle,jhword->Arg3*512,OFFSET_BEGINNING);
  263.        i=Read(td[Active].FileHandle,&jhword->Memory,l);
  264.        if(i==l)
  265.         {
  266.          jhword->Arg2=0;
  267.         }
  268.        else
  269.         {
  270.          jhword->Arg2=15+BIT15;
  271.         }
  272.       }
  273.     break;
  274.    case 3:
  275.      if(ud[Active].File==FALSE)
  276.       {
  277.        MotorCNT[Active]=ud[Active].Motor;
  278.        td[Active].Request->io_Command=CMD_UPDATE;
  279.        i=DoIO(td[Active].Request);
  280.        if(i!=0)
  281.         {
  282.          switch(i)
  283.           {
  284.            case 28:
  285.              jhword->Arg2=0+BIT15;
  286.             break;
  287.            case 29:
  288.              jhword->Arg2=15+BIT15;
  289.             break;
  290.            default:
  291.              jhword->Arg2=10+BIT15;
  292.             break;
  293.           }
  294.         }
  295.        else
  296.         {
  297.          jhword->Arg2=0;
  298.         }
  299.       }
  300.     break;
  301.    case 4:
  302.      if(ud[Active].File==FALSE)
  303.       {
  304.        jhword->Arg2=ChangeCheck(Active);
  305.       }
  306.      else
  307.       {
  308.        jhword->Arg2=1;
  309.       }
  310.     break;
  311.    case 5:
  312.      jhword->Arg2=ud[Active].Tracks*ud[Active].Heads*ud[Active].SectorsPerTrack;
  313.      jhword->Arg3=ud[Active].Tracks;
  314.      jhword->Arg4=ud[Active].Heads;
  315.      CalcFAT(Active);
  316.      if(ud[Active].File==FALSE) jhword->Arg7=0; else jhword->Arg7=1;
  317.     break;
  318.    case 6:
  319.      for(i=0;i<6;i++)
  320.       {
  321.        MotorOnOff(i,1);
  322.       }
  323.     break;
  324.    case 10:
  325.      Format();
  326.     break;
  327.    case 20:
  328.      Kopiere();
  329.     break;
  330.    case 100:
  331.      if(td[jhword->Arg2].Valid==FALSE)
  332.       {
  333.        jhword->Arg2=2+BIT15;
  334.       }
  335.      else
  336.       {
  337.        Active=jhword->Arg2;
  338.        jhword->Arg2=0;
  339.       }
  340.     break;
  341.    default:
  342.     break;
  343.   }
  344.  SendJanusInt(29);
  345. }
  346.  
  347.  
  348. /* Diskettenwechsel prüfen */
  349. WORD ChangeCheck(num)
  350.  UWORD num;
  351. {
  352.  REGISTER LONG i;
  353.  
  354.  td[num].Request->io_Command=TD_CHANGENUM;
  355.  DoIO(td[num].Request);
  356.  i=td[num].Request->io_Actual;
  357.  if(i!=td[num].Changes)
  358.   {
  359.    td[num].Changes=i;
  360.    return(0xFF);
  361.   }
  362.  return(1);
  363. }
  364.  
  365.  
  366. /* Laufwerke öffnen */
  367. VOID InstallAll()
  368. {
  369.  REGISTER LONG i;
  370.  
  371.  for(i=0;i<6;i++)
  372.   {
  373.    if(ud[i].File==FALSE)
  374.     {
  375.      InstallDevice(i);
  376.     }
  377.    else
  378.     {
  379.      InstallFile(i);
  380.     }
  381.   }
  382. }
  383.  
  384.  
  385. /* Laufwerke schließen */
  386. VOID UninstallAll()
  387. {
  388.  REGISTER LONG i;
  389.  
  390.  for(i=0;i<6;i++)
  391.   {
  392.    if(ud[i].File==FALSE)
  393.     {
  394.      UninstallDevice(i);
  395.     }
  396.    else
  397.     {
  398.      UninstallFile(i);
  399.     }
  400.   }
  401. }
  402.  
  403.  
  404. VOID InstallDevice(num)
  405.  UWORD num;
  406. {
  407.  
  408.  td[num].Port=CreatePort(0L,0L);
  409.  if(td[num].Port!=NULL)
  410.   {
  411.    td[num].Request=CreateExtIO(td[num].Port,200);
  412.    if(td[num].Request!=NULL)
  413.     {
  414.      td[num].Device=OpenDevice(&ud[num].Name,ud[num].Unit,td[num].Request,0);
  415.      if(td[num].Device!=0)
  416.       {
  417.        UninstallDevice(num);
  418.       }
  419.     }
  420.    else
  421.     {
  422.      UninstallDevice(num);
  423.     }
  424.   }
  425.  else
  426.   {
  427.    UninstallDevice(num);
  428.   }
  429. }
  430.  
  431.  
  432. VOID UninstallDevice(num)
  433.  UWORD num;
  434. {
  435.  
  436.  if(td[num].Valid==TRUE)
  437.   {
  438.    if(td[num].Device==0L) CloseDevice(td[num].Request);
  439.    if(td[num].Request) DeleteExtIO(td[num].Request);
  440.    if(td[num].Port) DeletePort(td[num].Port);
  441.    td[num].Valid=FALSE;
  442.   }
  443. }
  444.  
  445.  
  446. /* Datei installieren */
  447. VOID InstallFile(num)
  448.  UWORD num;
  449. {
  450.  REGISTER ULONG            i,j;
  451.  register struct FileLock *lock;
  452.  
  453.  td[num].Valid=FALSE;
  454.  lock=Lock(&ud[num].Name,ACCESS_READ);
  455.  if(lock!=NULL)
  456.   {
  457.    UnLock(lock);
  458.    td[num].FileHandle=Open(&ud[num].Name,MODE_READWRITE);
  459.    if(td[num].FileHandle!=NULL)
  460.     {
  461.      Seek(td[num].FileHandle,0,OFFSET_END);
  462.      i=Seek(td[num].FileHandle,0,OFFSET_BEGINNING);
  463.      j=512L*(ULONG)ud[num].Tracks*(ULONG)ud[num].Heads*(ULONG)ud[num].SectorsPerTrack;
  464.      if(i!=j)
  465.       {
  466.        MultiRequest("Inkompatible Dateilänge bei LW-Datei",&ud[num].Name,"Okay",NULL);
  467.        Close(td[num].FileHandle);
  468.       }
  469.      else
  470.       {
  471.        td[num].Valid=TRUE;
  472.       }
  473.     }
  474.   }
  475. }
  476.  
  477.  
  478. VOID UninstallFile(num)
  479.  UWORD num;
  480. {
  481.  
  482.  if(td[num].Valid==TRUE)
  483.   {
  484.    if(td[num].FileHandle) Close(td[num].FileHandle);
  485.    td[num].Valid=FALSE;
  486.   }
  487. }
  488.  
  489.  
  490. /* Installationsroutine */
  491. VOID OpenAll()
  492. {
  493.  REGISTER UWORD              i;
  494.  register struct MsgPort    *p;
  495.  register struct FileHandle *fh;
  496.  
  497.  ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
  498.  if(ATUtilitiesBase==NULL)
  499.   {
  500.    printf("Kann ATUtilities-Library nicht öffnen.\n");
  501.    CloseAll();
  502.   }
  503.  
  504.  GfxBase=OpenLibrary("graphics.library",0L);
  505.  IntuitionBase=OpenLibrary("intuition.library",0L);
  506.  if((GfxBase==NULL)||(IntuitionBase==NULL))
  507.   {
  508.    CloseAll();
  509.   }
  510.  
  511.  p=FindPort(TransferPort);
  512.  if(p!=NULL)
  513.   {
  514.    InfoRequest("ATUtilities Disk Transfer ist schon aktiv.");
  515.    CloseAll();
  516.   }
  517.  
  518.  MainTask=FindTask(NULL);
  519.  SetTaskPri(MainTask,10);
  520.  
  521.  JanusBase=OpenLibrary("janus.library",0L);
  522.  if(JanusBase==NULL)
  523.   {
  524.    ErrorRequest(ERROR_JANUS);
  525.    CloseAll();
  526.   }
  527.  
  528.  TaskSignal=AllocSignal(-1L);
  529.  if(TaskSignal==-1L)
  530.   {
  531.    ErrorRequest(ERROR_SIGNAL);
  532.    CloseAll();
  533.   }
  534.  
  535.  Port=CreatePort(TransferPort,0L);
  536.  if(Port==NULL)
  537.   {
  538.    ErrorRequest(ERROR_MPORT);
  539.    CloseAll();
  540.   }
  541.  
  542.  fh=Open(PrefsName,MODE_OLDFILE);
  543.  if(fh!=NULL)
  544.   {
  545.    Read(fh,&ud,sizeof(struct UDevice)*6);
  546.    Close(fh);
  547.   }
  548.  
  549.  InstallAll();
  550.  
  551.  mem=AllocMem(PUBLIC_PAGESIZE,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  552.  if(mem==NULL)
  553.   {
  554.    ErrorRequest(ERROR_ALLOC);
  555.    CloseAll();
  556.   }
  557.  
  558.  ExtSetupSig=CreatePublicHandler(29);
  559.  if(ExtSetupSig==NULL)
  560.   {
  561.    CloseAll();
  562.   }
  563.  
  564.  TaskPort=CreatePort("Disk Transfer Motor Task <Stop>",0L);
  565.  ReplyPort=CreatePort("Disk Transfer <Stop> Reply",0L);
  566.  if((TaskPort==NULL)||(ReplyPort==NULL))
  567.   {
  568.    ErrorRequest(ERROR_PORT);
  569.    CloseAll();
  570.   }
  571.  
  572.  MotorTask=CreateProcess(Motor,500,"Disk Transfer Motor Task",2);
  573.  if(MotorTask==NULL)
  574.   {
  575.    DeletePort(TaskPort);
  576.    InfoRequest("Kann Motor-Task nicht erstellen.\n");
  577.    CloseAll();
  578.   }
  579.  
  580.  app=CreateAppItem("ATUtilities Disk Transfer");
  581.  if(app!=NULL) AppSignalMask=app->SignalMask; else AppSignalMask=0;
  582.  
  583.  jhword=ExtSetupSig->WordAccess;
  584.  jhbyte=ExtSetupSig->ByteAccess;
  585.  PortSignal=Port->mp_SigBit;
  586.  PortSignalMask=(1L<<PortSignal);
  587.  JanusSignal=ExtSetupSig->JanusSignal;
  588.  JanusSignalMask=ExtSetupSig->JanusSignalMask;
  589.  TaskSignalMask=(1L<<TaskSignal);
  590.  WaitSignalMask=PortSignalMask+JanusSignalMask+TaskSignalMask+AppSignalMask;
  591. }
  592.  
  593.  
  594. /* Programmende */
  595. VOID CloseAll()
  596. {
  597.  if(app) DeleteAppItem(app);
  598.  if(MotorTask!=NULL)
  599.   {
  600.    Message.mn_Node.ln_Type=NT_MESSAGE;
  601.    Message.mn_ReplyPort=ReplyPort;
  602.    PutMsg(TaskPort,&Message);
  603.    WaitPort(ReplyPort);
  604.    DeletePort(ReplyPort);
  605.   }
  606.  if(ExtSetupSig) DeletePublicHandler(ExtSetupSig);
  607.  if(mem) FreeMem(mem,PUBLIC_PAGESIZE);
  608.  if(TaskSignal!=-1) FreeSignal(TaskSignal);
  609.  if(Port) DeletePort(Port);
  610.  UninstallAll();
  611.  if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
  612.  if(GfxBase) CloseLibrary(GfxBase);
  613.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  614.  if(JanusBase) CloseLibrary(JanusBase);
  615.  exit(0);
  616. }
  617.  
  618.  
  619. /* Einstellungs-Fenster */
  620. BOOL EinstellungenAendern()
  621. {
  622.  UBYTE                        text[40];
  623.  BOOL                         bool,ende;
  624.  REGISTER ULONG               Class;
  625.  REGISTER WORD                i,j,id;
  626.  register struct Window       *win;
  627.  register struct RastPort     *rp;
  628.  register struct Gadget       *gad;
  629.  register struct IntuiMessage *msg;
  630.  register struct TextFont     *opal;
  631.  
  632.  win=CreateStdWindow("ATUtilities - Disk Transfer Einstellungen",
  633.                      75,75,460,112+BorderHeight(),CLOSEWINDOW|GADGETUP,
  634.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE|GIMMEZEROZERO);
  635.  ende=FALSE;
  636.  if(win!=NULL)
  637.   {
  638.    rp=win->RPort;
  639.    opal=GetOpalFont();
  640.    SetFont(rp,opal);
  641.  
  642.    CreateBoolGadget(win,10,5,155,12,"Einstellungen Okay",1);
  643.    CreateBoolGadget(win,170,5,155,12,"Programm beenden",2);
  644.    CreateBoolGadget(win,335,5,50,12,"Info",3);
  645.    CreateBoolGadget(win,390,5,50,12,"Hilfe",4);
  646.    for(i=0,j=10;i<6;i++,j++)
  647.     {
  648.      sprintf(&text,"Laufwerk %ld:",i+1);
  649.      CreateBoolGadget(win,33,25+(i*14),120,12,&text,j);
  650.      CreateBoolGadget(win,10,25+(i*14),20,12,"!",i+100);
  651.      ZeigeLW(rp,i);
  652.     }
  653.  
  654.    bool=FALSE;
  655.    while(bool==FALSE)
  656.     {
  657.      WaitPort(win->UserPort);
  658.      msg=GetMsg(win->UserPort);
  659.      Class=msg->Class;
  660.      gad=msg->IAddress;
  661.      ReplyMsg(msg);
  662.      switch(Class)
  663.       {
  664.        case GADGETUP:
  665.          id=gad->GadgetID;
  666.          switch(id)
  667.           {
  668.            case 1:
  669.              bool=TRUE;
  670.             break;
  671.            case 2:
  672.              ende=TRUE; bool=TRUE;
  673.             break;
  674.            case 3:
  675.              ShowInfo();
  676.             break;
  677.            case 4:
  678.              Help(HelpName,0);
  679.             break;
  680.            default:
  681.              if((id>=10)&&(id<=15))
  682.               {
  683.                j=id-10;
  684.                EditiereLW(j);
  685.                ZeigeLW(rp,j);
  686.               }
  687.              if((id>=100)&&(id<=105))
  688.               {
  689.                j=id-100;
  690.                if(ud[j].File==FALSE)
  691.                 {
  692.                  if(td[j].Valid==TRUE)
  693.                   {
  694.                    Bearbeite(j);
  695.                   }
  696.                  else
  697.                   {
  698.                    MultiRequest("Dieses Device ist nocht nicht verfügbar.",
  699.                                 "Bitte prüfen Sie die Einstellungen.","Okay",0L);
  700.                   }
  701.                 }
  702.                else
  703.                 {
  704.                  BearbeiteFile(j);
  705.                 }
  706.               }
  707.             break;
  708.           }
  709.         break;
  710.        case CLOSEWINDOW:
  711.          bool=TRUE;
  712.         break;
  713.       }
  714.     }
  715.  
  716.    DeleteStdWindow(win);
  717.   }
  718.  if(ende) ende=ExitWarning();
  719.  return(ende);
  720. }
  721.  
  722.  
  723. /* Parameter ändern */
  724. VOID EditiereLW(num)
  725.  UWORD num;
  726. {
  727.  UBYTE                         text[10];
  728.  BOOL                          ende,f;
  729.  ULONG                         a,b,c,d;
  730.  REGISTER ULONG                Class;
  731.  REGISTER WORD                 i,j,id;
  732.  UBYTE                        *bDevice,
  733.                               *bUnit,
  734.                               *bBlocksPerTrack,
  735.                               *bTracks,
  736.                               *bHeads,
  737.                               *bMotor;
  738.  register struct Window       *win;
  739.  register struct RastPort     *rp;
  740.  register struct IntuiMessage *msg;
  741.  register struct TextFont     *opal;
  742.  register struct Gadget       *gad,*isFile;
  743.  struct FileHandle            *fh;
  744.  
  745.  win=CreateStdWindow("Laufwerksparameter editieren",
  746.                      225,90,400,100,CLOSEWINDOW|GADGETUP,
  747.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
  748.  ende=FALSE;
  749.  if(win!=NULL)
  750.   {
  751.    rp=win->RPort;
  752.    opal=GetOpalFont();
  753.    SetFont(rp,opal);
  754.  
  755.    CreateBoolGadget(win,10,15,100,12,"Okay",1);
  756.    CreateBoolGadget(win,120,15,100,12,"Abbruch",2);
  757.  
  758.    if(ud[num].File==FALSE)
  759.     {
  760.      isFile=CreateNToggleGadget(win,300,15,80,12,"Als Datei",100);
  761.     }
  762.    else
  763.     {
  764.      isFile=CreateSToggleGadget(win,300,15,80,12,"Als Datei",100);
  765.     }
  766.  
  767.    bDevice=CreateStringGadget(win,120,30,260,10,&ud[num].Name,100,3);
  768.    sprintf(&text,"%ld",ud[num].Unit);
  769.    bUnit=CreateIntegerGadget(win,120,45,60,10,&text,4,4);
  770.    sprintf(&text,"%ld",ud[num].Heads);
  771.    bHeads=CreateIntegerGadget(win,320,45,60,10,&text,5,5);
  772.    sprintf(&text,"%ld",ud[num].Tracks);
  773.    bTracks=CreateIntegerGadget(win,120,57,60,10,&text,7,6);
  774.    sprintf(&text,"%ld",ud[num].SectorsPerTrack);
  775.    bBlocksPerTrack=CreateIntegerGadget(win,320,57,60,10,&text,5,7);
  776.    sprintf(&text,"%ld",ud[num].Motor);
  777.    bMotor=CreateIntegerGadget(win,320,74,60,10,&text,5,8);
  778.  
  779.    WriteText(rp,15,37,"Device/Datei:");
  780.    WriteText(rp,15,52,"Unit:");
  781.    WriteText(rp,220,52,"S/L-Köpfe:");
  782.    WriteText(rp,15,64,"Spuren:");
  783.    WriteText(rp,220,64,"Sekt./Spur:");
  784.    WriteText(rp,15,82,"Motor-Ausschaltzeit nach x Sekunden:");
  785.  
  786.    ende=FALSE;
  787.    while(ende==FALSE)
  788.     {
  789.      WaitPort(win->UserPort);
  790.      msg=GetMsg(win->UserPort);
  791.      Class=msg->Class;
  792.      gad=msg->IAddress;
  793.      ReplyMsg(msg);
  794.      switch(Class)
  795.       {
  796.        case GADGETUP:
  797.          id=gad->GadgetID;
  798.          switch(id)
  799.           {
  800.            case 2:
  801.              ende=TRUE;
  802.             break;
  803.            case 1:
  804.              j=0;
  805.              a=atol(bUnit);
  806.              b=atol(bTracks);
  807.              c=atol(bHeads);
  808.              d=atol(bBlocksPerTrack);
  809.              i=atol(bMotor);
  810.              if(isFile->Flags & SELECTED) f=TRUE; else f=FALSE;
  811.              if(b<2)
  812.               { InfoRequest("Unzulässige Spurenanzahl."); j=1; }
  813.              if(c<1)
  814.               { InfoRequest("Unzulässige S/L-Kopfanzahl."); j++; }
  815.              if(d<2)
  816.               { InfoRequest("Unzulässige Anzahl von Sektoren/Spur."); j++; }
  817.              if(i>180)
  818.               { InfoRequest("Motor-Zeit nicht empfehlenswert (>180s)."); }
  819.              if(j==0)
  820.               {
  821.                if(strcmp(&ud[num].Name,bDevice)) j=1;
  822.                if(ud[num].Unit!=a) j=1;
  823.                if(ud[num].Tracks!=b) j=1;
  824.                if(ud[num].Heads!=c) j=1;
  825.                if(ud[num].SectorsPerTrack!=d) j=1;
  826.                strcpy(&ud[num].Name,bDevice);
  827.                ud[num].Motor=i;
  828.                ud[num].Unit=a;
  829.                ud[num].Tracks=b;
  830.                ud[num].Heads=c;
  831.                ud[num].SectorsPerTrack=d;
  832.                ud[num].File=f;
  833.                if(j==1)
  834.                 {
  835.                  td[num].Valid=FALSE;
  836.                  MultiRequest("Um Probleme mit MS-DOS zu vermeiden, wird",
  837.                               "das Laufwerk erst nach einem Reset aktiv.",
  838.                               "Okay",NULL);
  839.                 }
  840.                fh=Open(PrefsName,MODE_NEWFILE);
  841.                if(fh!=NULL)
  842.                 {
  843.                  Write(fh,&ud,sizeof(struct UDevice)*6);
  844.                  Close(fh);
  845.                 }
  846.                else
  847.                 {
  848.                  InfoRequest("Fehler beim Schreiben der Prefs-Datei.");
  849.                 }
  850.                ende=TRUE;
  851.               }
  852.             break;
  853.           }
  854.         break;
  855.        case CLOSEWINDOW:
  856.          ende=TRUE;
  857.         break;
  858.       }
  859.     }
  860.    DeleteStdWindow(win);
  861.   }
  862. }
  863.  
  864.  
  865. /* Parameter anzeigen */
  866. VOID ZeigeLW(rp,id)
  867.  struct RastPort *rp;
  868.  UWORD            id;
  869. {
  870.  UBYTE          size[20];
  871.  UBYTE          text[30];
  872.  REGISTER ULONG kb;
  873.  
  874.  kb=(ud[id].Heads*ud[id].Tracks*ud[id].SectorsPerTrack*512)/1024;
  875.  if(kb>=10000)
  876.   {
  877.    sprintf(&size,"%ld MB",kb/1024);
  878.   }
  879.  else
  880.   {
  881.    sprintf(&size,"%ld KB",kb);
  882.   }
  883.  if(ud[id].File==FALSE)
  884.   {
  885.    sprintf(&text,"%s  %s  Unit %ld",
  886.                   &size,&ud[id].Name,ud[id].Unit);
  887.   }
  888.  else
  889.   {
  890.    sprintf(&text,"%s  %s",&size,&ud[id].Name);
  891.   }
  892.  SetAPen(rp,0);
  893.  RectFill(rp,158,23+(id*14),450,36+(id*14));
  894.  SelectStdFPen(rp);
  895.  WriteText(rp,160,33+(id*14),&text);
  896. }
  897.  
  898.  
  899. /* Device-Laufwerk bearbeiten */
  900. VOID Bearbeite(num)
  901.  UWORD num;
  902. {
  903.  UBYTE                         text[40];
  904.  REGISTER BOOL                 ende,bool;
  905.  REGISTER ULONG                Class;
  906.  REGISTER WORD                 i,j,id;
  907.  register struct Window       *win;
  908.  register struct RastPort     *rp;
  909.  register struct Gadget       *gad;
  910.  register struct IntuiMessage *msg;
  911.  register struct TextFont     *opal;
  912.  register struct Gadget       *verify;
  913.  BOOL                          v;
  914.  ULONG                         BytesPerTrack;
  915.  ULONG                         Track;
  916.  UBYTE                        *FormatMemory;
  917.  
  918.  win=CreateStdWindow("Speichermedium bearbeiten",
  919.                      225,90,300,76,CLOSEWINDOW|GADGETUP,
  920.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
  921.  ende=FALSE;
  922.  if(win!=NULL)
  923.   {
  924.    rp=win->RPort;
  925.    opal=GetOpalFont();
  926.    SetFont(rp,opal);
  927.  
  928.    CreateBoolGadget(win,10,12,100,12,"Okay",1);
  929.    CreateBoolGadget(win,10,30,119,12,"Hard-Format",2);
  930.    CreateBoolGadget(win,10,44,172,12,"Prüfe auf Fehler",3);
  931.    verify=CreateSToggleGadget(win,132,30,50,12,"Verify",100);
  932.    DrawNTextBorder(win,10,58,280,12,"Kein Fehler aufgetreten.");
  933.    DrawNTextBorder(win,190,30,100,12,"0");
  934.    DrawNTextBorder(win,190,44,100,12,"0 %");
  935.  
  936.    ende=FALSE;
  937.    while(ende==FALSE)
  938.     {
  939.      WaitPort(win->UserPort);
  940.      msg=GetMsg(win->UserPort);
  941.      Class=msg->Class;
  942.      gad=msg->IAddress;
  943.      ReplyMsg(msg);
  944.      switch(Class)
  945.       {
  946.        case GADGETUP:
  947.          id=gad->GadgetID;
  948.          switch(id)
  949.           {
  950.            case 2:
  951.            case 3:
  952.              DrawCNTextBorder(win,10,58,280,12,"Kein Fehler aufgetreten.");
  953.              if(verify->Flags & SELECTED) v=TRUE; else v=FALSE;
  954.              if(id==3)
  955.               {
  956.                bool=MultiRequest("Wollen Sie den Datenträger auf",
  957.                                  "Fehler überprüfen ?",
  958.                                  "Ja, Prüfen","Nein, Zurück");
  959.               }
  960.              else
  961.               {
  962.                bool=MultiRequest("Hard-Format: Alle Daten werden gelöscht!",
  963.                                  "Sind Sie wirklich sicher ?",
  964.                                  "Ja, Format","NEIN! Zurück");
  965.               }
  966.              if(bool==TRUE)
  967.               {
  968.                MotorCNT[num]=5;
  969.                BytesPerTrack=ud[num].SectorsPerTrack*ud[num].Heads*512;
  970.                FormatMemory=AllocMem(BytesPerTrack,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  971.                if(FormatMemory!=NULL)
  972.                 {
  973.                  SetDrMd(rp,JAM2);
  974.                  j=0;
  975.                  for(Track=0;Track<ud[num].Tracks;Track++)
  976.                   {
  977.                    sprintf(&text,"   %ld   ",Track);
  978.                    DrawNTextBorder(win,190,30,100,12,&text);
  979.                    sprintf(&text,"   %3ld %%   ",((Track*100)/(ud[num].Tracks-1)));
  980.                    DrawNTextBorder(win,190,44,100,12,&text);
  981.                    if(ud[num].File==FALSE)
  982.                     {
  983.                      if(id==3)
  984.                       {
  985.                        td[num].Request->io_Data=FormatMemory;
  986.                        td[num].Request->io_Length=BytesPerTrack;
  987.                        td[num].Request->io_Offset=Track*BytesPerTrack;
  988.                        td[num].Request->io_Command=CMD_READ;
  989.                        i=DoIO(td[num].Request);
  990.                        if(i!=0)
  991.                         {
  992.                          if(i==29)
  993.                           {
  994.                            InfoRequest("Das Medium ist nicht eingelegt.");
  995.                            Track=ud[num].Tracks;
  996.                           }
  997.                          else
  998.                           {
  999.                            sprintf(&text,"Fehler #%ld auf Track %ld.",i,Track);
  1000.                            DrawCNTextBorder(win,10,58,280,12,&text);
  1001.                           }
  1002.                          j++;
  1003.                         }
  1004.                       }
  1005.                      else
  1006.                       {
  1007.                        td[num].Request->io_Data=FormatMemory;
  1008.                        td[num].Request->io_Length=BytesPerTrack;
  1009.                        td[num].Request->io_Offset=Track*BytesPerTrack;
  1010.                        td[num].Request->io_Command=TD_FORMAT;
  1011.                        i=DoIO(td[num].Request);
  1012.                        if(i!=0)
  1013.                         {
  1014.                          sprintf(&text,"Format: Fehler #%ld auf Track %ld.",i,Track);
  1015.                          DrawCNTextBorder(win,10,58,280,12,&text);
  1016.                          j++;
  1017.                          if(i==28)
  1018.                           {
  1019.                            InfoRequest("Das Medium ist schreibgeschützt.");
  1020.                            Track=ud[num].Tracks;
  1021.                           }
  1022.                          else if(i==29)
  1023.                           {
  1024.                            InfoRequest("Das Medium ist nicht eingelegt.");
  1025.                            Track=ud[num].Tracks;
  1026.                           }
  1027.                         }
  1028.                        if((v==TRUE)&&(Track<ud[num].Tracks))
  1029.                         {
  1030.                          td[num].Request->io_Data=FormatMemory;
  1031.                          td[num].Request->io_Length=BytesPerTrack;
  1032.                          td[num].Request->io_Offset=Track*BytesPerTrack;
  1033.                          td[num].Request->io_Command=CMD_READ;
  1034.                          i=DoIO(td[num].Request);
  1035.                          if(i!=0)
  1036.                           {
  1037.                            sprintf(&text,"Verify: Fehler #%ld auf Track %ld.",i,Track);
  1038.                            DrawCNTextBorder(win,10,58,280,12,&text);
  1039.                            j++;
  1040.                           }
  1041.                         }
  1042.                       }
  1043.                     }
  1044.                   }
  1045.                  if(j==0)
  1046.                   {
  1047.                    if(id==3) InfoRequest("Der Datenträger ist fehlerfrei.");
  1048.                   }
  1049.                  else
  1050.                   {
  1051.                    if(id==3)
  1052.                     {
  1053.                      sprintf(&text,"%ld Fehler gefunden worden.",j);
  1054.                      MultiRequest("Bei der Überprüfung sind",&text,"Okay",NULL);
  1055.                     }
  1056.                    else
  1057.                     {
  1058.                      sprintf(&text,"%ld Fehler aufgetreten.",j);
  1059.                      MultiRequest("Bei der Formatierung sind",&text,"Okay",NULL);
  1060.                     }
  1061.                   }
  1062.                  FreeMem(FormatMemory,BytesPerTrack);
  1063.                 }
  1064.               }
  1065.             break;
  1066.            case 1:
  1067.              ende=TRUE;
  1068.             break;
  1069.           }
  1070.         break;
  1071.        case CLOSEWINDOW:
  1072.          ende=TRUE;
  1073.         break;
  1074.       }
  1075.     }
  1076.    DeleteStdWindow(win);
  1077.   }
  1078. }
  1079.  
  1080.  
  1081. /* FAT berechnen */
  1082. VOID CalcFAT(num)
  1083.  UWORD num;
  1084. {
  1085.  REGISTER UWORD anz,i;
  1086.  REGISTER ULONG bytes,plus,sek,spc;
  1087.  
  1088.  
  1089.  sek=ud[num].Tracks*ud[num].Heads*ud[num].SectorsPerTrack;
  1090.  if(sek>4096)
  1091.   {
  1092.    bytes=sek*2;       /* FAT 16-Bit */
  1093.   }
  1094.  else
  1095.   {
  1096.    bytes=(sek*3)/2;   /* FAT 12-Bit */
  1097.   }
  1098.  plus=0;
  1099.  anz=0;
  1100.  for(i=0;i<32000;i++)
  1101.   {
  1102.    if(plus>=bytes)
  1103.     {
  1104.      spc=1;
  1105.      if(anz>15)
  1106.       {
  1107.        do
  1108.         {
  1109.          spc=spc*2;
  1110.          anz=anz/2;
  1111.         } while(anz>15);
  1112.       }
  1113.      jhword->Arg5=anz;
  1114.      jhbyte->Arg6=spc;
  1115.      return;
  1116.     }
  1117.    else
  1118.     {
  1119.      plus+=512;
  1120.      anz++;
  1121.     }
  1122.   }
  1123. }
  1124.  
  1125.  
  1126. /* File-Laufwerk bearbeiten */
  1127. VOID BearbeiteFile(num)
  1128.  UWORD num;
  1129. {
  1130.  UBYTE                       text[35];
  1131.  REGISTER BOOL               bool;
  1132.  REGISTER UBYTE             *mem;
  1133.  REGISTER ULONG              i,j,k,l;
  1134.  register struct FileHandle *fh;
  1135.  register struct Window     *win;
  1136.  register struct RastPort   *rp;
  1137.  struct TextFont            *opal;
  1138.  struct IntuiMessage        *msg;
  1139.  
  1140.  if(td[num].Valid==FALSE)
  1141.   {
  1142.    bool=MultiRequest("Es existiert keine Laufwerksdatei.",
  1143.                      "Möchten Sie eine erstellen ?",
  1144.                      "Ja, Erstellen","Nein, Zurück");
  1145.    if(bool==TRUE)
  1146.     {
  1147.      j=512*ud[num].SectorsPerTrack*ud[num].Heads;
  1148.      mem=AllocMem(j,MEMF_CLEAR|MEMF_PUBLIC);
  1149.      if(mem!=NULL)
  1150.       {
  1151.        fh=Open(&ud[num].Name,MODE_NEWFILE);
  1152.        if(fh!=NULL)
  1153.         {
  1154.          win=CreateStdWindow("Laufwerksdatei erstellen",
  1155.                              75,90,300,30,GADGETUP|CLOSEWINDOW,
  1156.                              WINDOWCLOSE|WINDOWDEPTH|ACTIVATE|WINDOWDRAG);
  1157.          if(win!=NULL)
  1158.           {
  1159.            opal=GetOpalFont();
  1160.            rp=win->RPort;
  1161.            SetFont(rp,opal);
  1162.            CreateBoolGadget(win,10,15,120,12,"Stop !",1);
  1163.            bool=FALSE;
  1164.            if(win!=NULL)
  1165.             {
  1166.              for(i=0;i<ud[num].Tracks;i++)
  1167.               {
  1168.                sprintf(&text,"Track %ld von %ld",i,ud[num].Tracks);
  1169.                DrawCNTextBorder(win,140,15,150,12,&text);
  1170.                k=Write(fh,mem,j);
  1171.                if(k!=j)
  1172.                 {
  1173.                  InfoRequest("Schreibfehler!");
  1174.                  i=ud[num].Tracks;
  1175.                  bool=TRUE;
  1176.                 }
  1177.                msg=GetMsg(win->UserPort);
  1178.                if(msg!=NULL)
  1179.                 {
  1180.                  InfoRequest("Stop!");
  1181.                  i=ud[num].Tracks;
  1182.                  bool=TRUE;
  1183.                 }
  1184.               }
  1185.              if(bool==FALSE)
  1186.               {
  1187.                td[num].FileHandle=fh;
  1188.                td[num].Valid=TRUE;
  1189.               }
  1190.              else
  1191.               {
  1192.                Close(fh);
  1193.                DeleteFile(&ud[num].Name);
  1194.               }
  1195.             }
  1196.            DeleteStdWindow(win);
  1197.           }
  1198.          else
  1199.           {
  1200.            Close(fh);
  1201.            DeleteFile(&ud[num].Name);
  1202.            ErrorRequest(ERROR_ALLOC);
  1203.           }
  1204.         }
  1205.        else InfoRequest("Laufwerksdatei läßt sich nicht erstellen.");
  1206.        FreeMem(mem,j);
  1207.       }
  1208.      else ErrorRequest(ERROR_ALLOC);
  1209.     }
  1210.   }
  1211.  else
  1212.   {
  1213.    win=CreateStdWindow("Laufwerksdatei-Information",75,90,300,90,
  1214.                        CLOSEWINDOW|GADGETUP,
  1215.                        WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
  1216.    if(win!=NULL)
  1217.     {
  1218.      opal=GetOpalFont();
  1219.      rp=win->RPort;
  1220.      SetFont(rp,opal);
  1221.      CreateBoolGadget(win,10,15,120,12,"Okay",1);
  1222.  
  1223.      sprintf(&text,"Spuren: %ld",ud[num].Tracks);
  1224.      DrawNTextBorder(win,10,30,280,12,&text);
  1225.      sprintf(&text,"S/L-Köpfe: %ld",ud[num].Heads);
  1226.      DrawNTextBorder(win,10,45,280,12,&text);
  1227.      sprintf(&text,"Sektoren/Spur: %ld",ud[num].SectorsPerTrack);
  1228.      DrawNTextBorder(win,10,60,280,12,&text);
  1229.      sprintf(&text,"KBytes: %ld",(ud[num].Tracks*ud[num].SectorsPerTrack*ud[num].Heads)/2);
  1230.      DrawNTextBorder(win,10,75,280,12,&text);
  1231.  
  1232.      WaitPort(win->UserPort);
  1233.      DeleteStdWindow(win);
  1234.     }
  1235.   }
  1236. }
  1237.  
  1238.  
  1239. /* Motor-Kontrollprozeß */
  1240. VOID Motor()
  1241. {
  1242.  register struct Message *msg;
  1243.  
  1244.  geta4();
  1245.  do
  1246.   {
  1247.    Delay(50);
  1248.    Signal(MainTask,TaskSignalMask);
  1249.    msg=GetMsg(TaskPort);
  1250.   }
  1251.  while(msg==NULL);
  1252.  DeletePort(TaskPort);
  1253.  ReplyMsg(msg);
  1254.  Exit(0);
  1255. }
  1256.  
  1257.  
  1258. /* Motor ein- und ausschalten */
  1259. VOID MotorOnOff(num,status)
  1260.  UWORD num;
  1261.  UWORD status;
  1262. {
  1263.  
  1264.  if(td[num].Valid==TRUE)
  1265.   {
  1266.    if(ud[num].File==FALSE)
  1267.     {
  1268.      td[num].Request->io_Command=TD_MOTOR;
  1269.      td[num].Request->io_Length=status;
  1270.      SendIO(td[num].Request);
  1271.      if(status) MotorCNT[num]=ud[num].Motor;
  1272.     }
  1273.   }
  1274. }
  1275.  
  1276.  
  1277. /* Datenträger formatieren */
  1278. VOID Format()
  1279. {
  1280.  REGISTER ULONG  tSize;
  1281.  REGISTER UBYTE *fBuffer;
  1282.  REGISTER UWORD  res,i;
  1283.  
  1284.  res=0;
  1285.  if(ud[Active].File==FALSE)
  1286.   {
  1287.    tSize=512*ud[Active].SectorsPerTrack*ud[Active].Heads;
  1288.    fBuffer=AllocMem(tSize,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1289.    if(fBuffer!=NULL)
  1290.     {
  1291.      td[Active].Request->io_Data=fBuffer;
  1292.      td[Active].Request->io_Length=tSize;
  1293.      td[Active].Request->io_Offset=jhword->Arg2*tSize;
  1294.      td[Active].Request->io_Command=TD_FORMAT;
  1295.      i=DoIO(td[Active].Request);
  1296.      if(i==0)
  1297.       {
  1298.        if(jhword->Arg3==1)
  1299.         {
  1300.          td[Active].Request->io_Command=CMD_READ;
  1301.          i=DoIO(td[Active].Request);
  1302.          if(i!=0) res=3;
  1303.         }
  1304.       } else res=2;
  1305.      MotorCNT[Active]=ud[Active].Motor;
  1306.      FreeMem(fBuffer,tSize);
  1307.     }
  1308.    else res=1;
  1309.   }
  1310.  jhword->Arg2=res;
  1311. }
  1312.  
  1313.  
  1314. /* Datenträger kopieren */
  1315. VOID Kopiere()
  1316. {
  1317.  REGISTER ULONG  tSize;
  1318.  REGISTER UBYTE *fBuffer;
  1319.  REGISTER UWORD  res,i;
  1320.  
  1321.  res=0;
  1322.  tSize=512*ud[Active].SectorsPerTrack*ud[Active].Heads;
  1323.  fBuffer=AllocMem(tSize,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1324.  if(fBuffer!=NULL)
  1325.   {
  1326.    if(ud[Active].File==FALSE)
  1327.     {
  1328.      td[Active].Request->io_Data=fBuffer;
  1329.      td[Active].Request->io_Length=tSize;
  1330.      td[Active].Request->io_Offset=jhword->Arg2*tSize;
  1331.      td[Active].Request->io_Command=CMD_READ;
  1332.      i=DoIO(td[Active].Request);
  1333.     }
  1334.    else
  1335.     {
  1336.      Seek(td[Active].FileHandle,jhword->Arg2*tSize,OFFSET_BEGINNING);
  1337.      i=Read(td[Active].FileHandle,fBuffer,tSize);
  1338.      if(i!=tSize) i=1; else i=0;
  1339.     }
  1340.    if(i==0)
  1341.     {
  1342.      if(ud[jhword->Arg3].File==FALSE)
  1343.       {
  1344.        td[jhword->Arg3].Request->io_Data=fBuffer;
  1345.        td[jhword->Arg3].Request->io_Length=tSize;
  1346.        td[jhword->Arg3].Request->io_Offset=jhword->Arg2*tSize;
  1347.        td[jhword->Arg3].Request->io_Command=TD_FORMAT;
  1348.        i=DoIO(td[jhword->Arg3].Request);
  1349.        if(i==0)
  1350.         {
  1351.          if(jhword->Arg4==1)
  1352.           {
  1353.            td[jhword->Arg3].Request->io_Command=CMD_READ;
  1354.            i=DoIO(td[jhword->Arg3].Request);
  1355.            if(i!=0) res=4;
  1356.           }
  1357.         } else res=3;
  1358.       }
  1359.      else
  1360.       {
  1361.        Seek(td[jhword->Arg3].FileHandle,jhword->Arg2*tSize,OFFSET_BEGINNING);
  1362.        i=Write(td[jhword->Arg3].FileHandle,fBuffer,tSize);
  1363.        if(i!=tSize) res=3;
  1364.       }
  1365.     } else res=2;
  1366.    MotorCNT[Active]=ud[Active].Motor;
  1367.    MotorCNT[jhword->Arg3]=ud[jhword->Arg3].Motor;
  1368.    FreeMem(fBuffer,tSize);
  1369.   } else res=1;
  1370.  jhword->Arg2=res;
  1371. }
  1372.  
  1373.  
  1374. /* Information */
  1375. VOID ShowInfo()
  1376. {
  1377.  InformationBox("ATUtilities Disk Transfer - Information",
  1378.                 "$VER: Disk Transfer - Version 4.0",
  1379.                 "Copyright (C) 1993 by",
  1380.                 "Thomas Dreibholz",
  1381.                 "All rights reserved.",
  1382.                 "AT:Icons/Utility");
  1383. }
  1384.  
  1385.